package com.example.score;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.SavedStateViewModelFactory;
import androidx.lifecycle.ViewModelProvider;
import androidx.lifecycle.ViewModelProviders;

import android.os.Bundle;
import android.os.PersistableBundle;
import android.util.Log;

import com.example.score.databinding.ActivityMainBinding;

public class MainActivity extends AppCompatActivity {

    MyViewModel myViewModel;
    ActivityMainBinding binding;

    final static String KEY_NUMBER_ATEAM = "my_number_aTeam";
    final static String KEY_NUMBER_BTEAM = "my_number_bTeam";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        binding = DataBindingUtil.setContentView(this,R.layout.activity_main);
        myViewModel = new ViewModelProvider(this,new SavedStateViewModelFactory(getApplication(),this)).get(MyViewModel.class);

        //第一次运行 这个是空的
//        if (savedInstanceState != null){
//            myViewModel.getaTeamScore().setValue(savedInstanceState.getInt(KEY_NUMBER));
//        }

        binding.setData(myViewModel);
        binding.setLifecycleOwner(this);

    }

//    @Override
//    protected void onSaveInstanceState(@NonNull Bundle outState) {
//        super.onSaveInstanceState(outState);
//
//        System.out.println("onSaveInstanceState");
//        outState.putInt(KEY_NUMBER,myViewModel.getaTeamScore().getValue());
//    }
}